import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/widget/asr_app_bar.dart';
import 'package:webview_flutter/webview_flutter.dart';

class H5Page extends StatefulWidget {
  final Map arguments;
  H5Page({required this.arguments});

  @override
  _H5PageState createState() {
    // TODO: implement createState
    return _H5PageState();
  }
}

class _H5PageState extends State<H5Page> {
  late WebViewController _controller;
  late String title;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    if (Platform.isAndroid) {
      // WebView.platform = SurfaceAndroidWebView();
    }
    title = widget.arguments['title'] ?? '';
    print('url====='+widget.arguments["url"]);

  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AsrAppBar(
        titleText: title ?? '',
        elevation: 1,
        leadFun: ()async{
          if(await _controller.canGoBack()){
            _controller.goBack();
          }else{
            Navigator.of(context).pop();
          }
        },
      ),
      body: Container(
        child: WebViewWidget(
          controller: _controller,
          // backgroundColor: Colors.white,
          // javascriptMode: JavascriptMode.unrestricted,
          // initialUrl: widget.arguments["url"],
          // onWebViewCreated: (controller) {
          //   _controller = controller;
          //   _controller.clearCache();
          //   showLoading(maskType: EasyLoadingMaskType.none);
          // },
          // javascriptChannels: const <JavascriptChannel>{
          // },
          // onPageFinished: (url) {
          //   hideLoading();
          // },
          // onWebResourceError: (error) {
          //   hideLoading();
          // },
          // onPageStarted: (str) {},
        ),
      ),
    );
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    hideLoading();
  }
}
